package test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**连接mysql数据库
 */
public class DBConn {
	//数据库连接信息
	private static final String URL = "jdbc:mysql://localhost:3306/blog";
	private static final String UNAME = "root";
	private static final String PSW = "1234";
	private static Connection conn =null;
	
	//静态代码块：注册驱动，进行连接
	static{
		
		try {//注册驱动
			Class.forName("com.mysql.jdbc.Driver");
			
			//获取连接
			conn = DriverManager.getConnection(URL, UNAME, PSW);
		} catch (ClassNotFoundException e) {
			System.out.println("注册驱动失败。。。");
		} catch (SQLException e) {
			System.out.println("获取连接失败。。。");
		}
	}
	
	//对外提供连接
	public static Connection getConnetion(){
		return conn;
	}
}
